package cn.yunhe.services;

import cn.yunhe.dao.IUserAddress;
import cn.yunhe.entity.userentity.UserAddress;
import cn.yunhe.util.SqlSessionFactoryUtil;
import net.sf.json.JSONArray;
import org.apache.ibatis.session.SqlSession;

import java.util.List;
import java.util.Map;

/**
 * 苏明辉
 */
public class UserAddressServices {
    SqlSession sqlSession = SqlSessionFactoryUtil.getSqlSession();
    IUserAddress iUserAddress = sqlSession.getMapper(IUserAddress.class);

    /**
     * 增加地址
     */
    public int addUserAddress(UserAddress userAddress) {
       try{
           int flag = iUserAddress.addUserAddress(userAddress);
           sqlSession.commit();
           return flag;
       }finally {
           sqlSession.close();
       }


    }

    /**
     * 用户地址展示
     */
    public JSONArray getUserAddressById() {
        JSONArray jsonArray=new JSONArray();
        List<UserAddress> userAddressList = iUserAddress.getUserAddressById(1);
        jsonArray.addAll(userAddressList);
        return jsonArray;
    }
    /**
     * 用户地址删除
     */
    public int deleteUserAddress(UserAddress userAddress){
     int flag=iUserAddress.deleteUserAddress(userAddress);
     sqlSession.commit();
     return  flag;
    }
    /**
     * 用户地址修改
     */
    public int updateUserAddress(Map map){
        int flag=iUserAddress.updateUserAddress(map);


        sqlSession.commit();
        return flag;

    }
}


